package com.zuipin.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zuipin.entity.product.ProductImg;
import com.zuipin.framework.annotation.Inject;
import com.zuipin.framework.annotation.Json;
import com.zuipin.framework.annotation.Jsons;
import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.emuns.ErrorCode;
import com.zuipin.framework.exception.CustomException;
import com.zuipin.framework.result.Result;
import com.zuipin.service.IProductImgService;
import com.zuipin.vo.BackProductImgVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 商品相册信息Controller
 *
 * @ClassName ProductImgController
 * @author wangcongyi
 * @date 2017年6月9日 上午9:21:13
 */
@Controller
@RequestMapping(value = "/productImg")
@Api(value = "商品相册", description = "商品相册信息-wangcongyi")
public class ProductImgController {
	
	@Resource
	private IProductImgService productImgService;
	
	@Jsons({ @Json(type = ProductImg.class, include = "id,proExtId,sysId,type,imgUrl,pcViewTag,wapViewTag"), })
	@RequestMapping(value = "/selectProImgs", method = RequestMethod.GET)
	@ApiOperation(value = "查找商品相册列表信息", notes = "查找商品相册列表信息")
	@Valids({ @Valid(name = "productImg.proExtId", required = true), @Valid(name = "productImg.sysId", required = true), })
	@ApiImplicitParams({ @ApiImplicitParam(name = "productImg.proExtId", value = "商品拓展信息ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "productImg.sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"), })
	public Result<?> selectProImgs(@Inject @ApiIgnore ProductImg productImg) {
		Result<List<ProductImg>> result = new Result<>();
		result.setData(productImgService.selectProImgs(productImg));
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/updateImg", method = RequestMethod.POST)
	@ApiOperation(value = "更新商品图片-huihang", notes = "更新商品图片-huihang")
	@Valids({ @Valid(name = "backProductImgVo.proExtId", required = true, maxLength = 20), @Valid(name = "backProductImgVo.sysId", required = true), })
	@ApiImplicitParams({ /*@ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
							@ApiImplicitParam(name = "proExtId", value = "平台商品ID", required = true, dataType = "long", paramType = "query"),
							@ApiImplicitParam(name = "updateId", value = "修改人ID", required = false, dataType = "long", paramType = "query"),*/ })
	public Result<?> updateImg(@RequestBody @ApiParam BackProductImgVo backProductImgVo) throws CustomException {
		return productImgService.updateByProExtIdAndSysId(backProductImgVo.getProductImgs(), backProductImgVo.getProExtId(), backProductImgVo.getSysId(),
				backProductImgVo.getUpdateId());
	}
	
}
